<template>
        <el-dialog title="成绩导出" :visible.sync="showDialog">
            <el-form :model="oForm" class="o-form" label-width="90px">
                <el-form-item label="活动名称：">
                    <el-select placeholder="活动名称" v-model="oForm.activityId">
                        <el-option v-for="item in actives.list" :key="item.id" :label="item.name" :value="item.id">
                        </el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="校区名称：">
                    <el-select v-model="oForm.schoolId" multiple :collapse-tags="true" placeholder="校区">
                        <el-option v-for="item in school.schoolObj.list" :label="item.name" :value="item.id" :key="item.id"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="学期：">
                    <el-select v-model="oForm.baseTrimesterId" placeholder="学期">
                        <el-option v-for="item in condition.termObj.list" :label="item.name" :value="item.id" :key="item.id"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="年级：">
                    <el-select v-model="oForm.baseSectionId" multiple :collapse-tags="true" placeholder="年级">
                        <el-option v-for="item in condition.gradeObj.list" :label="item.name" :value="item.id" :key="item.id"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="学科：">
                    <el-select v-model="oForm.dataSubject" multiple :collapse-tags="true" placeholder="学科">
                        <el-option v-for="item in condition.subjectList" :key="item.id" :label="item.name" :value="item.id">
                        </el-option>
                    </el-select>
                </el-form-item>
                <el-form-item class="btn">
                    <el-button class="light-btn" @click="exportTable">导出</el-button>
                </el-form-item>
            </el-form>
        </el-dialog>
</template>
<script>
import io from 'lib/io'
import storage from 'lib/storage'
import { mapState, mapActions, mapGetters } from 'vuex'
export default {
  name:'export-ach',
  data () {
      return {
            oForm: {
                activityId: '',
                schoolId: [],
                baseTrimesterId: '',
                baseSectionId: [],
                dataSubject: []
            },
            actives: {},
            showDialog:false
      }
  },
    computed: {
        ...mapState(['classes', 'condition', 'school']),
    },
    async created() {
        // this.findBaseLevelPage({ pageIndex: 1, pageSize: 10000000 })
        this.getActiveList()
        // let cond = sessionStorage.getItem('classCond')
        // if (cond) {
        //     this.form = JSON.parse(cond)
        // }
        // this.getClass()
        Promise.all([
            this.findBaseTermPage({ pageIndex: 1, pageSize: 10000000 }),
            this.findBaseSchoolPage({ pageIndex: 1, pageSize: 10000000, tag: 2 }),
            this.findSubjectsData({ pageIndex: 1, pageSize: 10000000 }),
            this.findBaseSectionPage({ pageIndex: 1, pageSize: 10000000 })
        ]).then(() => {
            this.oForm.baseTrimesterId = this.condition.termObj && this.condition.termObj.list[0].id
            this.school.schoolObj && this.school.schoolObj.list.map((item, i) => {
                this.oForm.schoolId.push(item.id)
            })
            this.condition.subjectList && this.condition.subjectList.map((item, i) => {
                this.oForm.dataSubject.push(item.id)
            })
            this.condition.gradeObj && this.condition.gradeObj.list.map((item, i) => {
                if (item.name === '高一' || item.name === '高二' || item.name === '高三') {
                    this.oForm.baseSectionId.push(item.id)
                }
            })
        })
    },
  methods: {
        ...mapActions(['findBaseSectionPage', 'findBaseTermPage', 'findBaseLevelPage', 'findBaseSchoolPage', 'findSubjectsData']),
        changeDialog(){
            this.showDialog=!this.showDialog
        },
        async getActiveList() {
            let { data } = await io.post6(io.examModelActivityList, { pageIndex: 1, pageSize: 1000000, isUse: 1 })
            if (data.success) {
                this.actives = data.data
                this.oForm.activityId = data.data.list[0]&& data.data.list[0].id
            }
        },
        exportTable() {
            if (!this.oForm.schoolId.length) {
                this.$message('请选择校区')
                return
            }
            this.showDialog = false
            window.open(`${io.examReportExport}?examModelActivityId=${this.oForm.activityId}&baseSchoolIds=${this.oForm.schoolId.join(',')}&baseTrimesterId=${this.oForm.baseTrimesterId}&baseSectionIds=${this.oForm.baseSectionId.join(',')}&dataSubjectIds=${this.oForm.dataSubject.join(',')}&accessToken=${storage.getAccessToken()}`)
        },
  }
}
</script>

<style lang="stylus" scoped>
.o-form
    width 500px
    margin 30px auto 0
    text-align center
    .el-select
        width 100%
</style>
